//
//  RecordingView.m
//  YSSmartHome
//
//  Created by yanghao on 2016/12/29.
//  Copyright © 2016年 yahaong. All rights reserved.
//

#import "RecordingView.h"
#import "YHMarcros.h"

@interface RecordingView ()

@property (nonatomic, strong) UIView* m_viewCover;
@property (nonatomic, strong) UIImageView* m_imgBackground;
@property (nonatomic, strong) UIView* m_viewContent;
@property (nonatomic, strong) UIImageView* m_imgVolume;
@property (nonatomic, strong) UILabel* m_lblTitle;
@end
@implementation RecordingView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
        UITapGestureRecognizer* tapGes = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(coverViewClick)];
        [_m_viewCover addGestureRecognizer:tapGes];
    }
    return self;
}

- (void)setupUI
{
    [self addSubview:self.m_viewCover];
    [self.m_viewCover mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    [self addSubview:self.m_viewContent];
    [self.m_viewContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.width.equalTo(kIphoneSize_Widith(90));
        make.height.equalTo(kIphoneSize_Height(80));
    }];
    [self.m_viewContent addSubview:self.m_imgBackground];
    [self.m_imgBackground mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.m_viewContent);
    }];
    [self.m_viewContent addSubview:self.m_imgVolume];
    [self.m_imgVolume mas_makeConstraints:^(MASConstraintMaker *make) {
          make.edges.equalTo(self.m_viewContent);
    }];
    [self.m_viewContent addSubview:self.m_lblTitle];
    [self.m_lblTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.m_viewContent);
        make.bottom.equalTo(self.m_viewContent).offset(kIphoneSize_Height(-5));
    }];
}
- (void)setVolumeType:(ZTVolumeType)volumeType
{
    switch (volumeType) {
        case ZTVolumeTypeNone:
            self.m_imgVolume.image = [UIImage imageNamed:@"voice2_"];
            break;
        case ZTVolumeTypeOne:
            self.m_imgVolume.image = [UIImage imageNamed:@"voice3_"];
            break;
        case ZTVolumeTypeTwo:
            self.m_imgVolume.image = [UIImage imageNamed:@"voice4_"];
            break;
        case ZTVolumeTypeThree:
            self.m_imgVolume.image = [UIImage imageNamed:@"voice5_"];
            break;
        default:
            break;
    }
}

- (void)coverViewClick
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(recordingViewClick)]) {
        [self.delegate recordingViewClick];
    }
}
#pragma mark - lazy loading

- (UIView *)m_viewCover
{
    if (!_m_viewCover)
    {
        _m_viewCover = [[UIView alloc] init];
        _m_viewCover.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    }
    return _m_viewCover;
}
- (UIView *)m_viewContent
{
    if (!_m_viewContent)
    {
        _m_viewContent = [[UIView alloc] init];
    }
    return _m_viewContent;
}

- (UIImageView *)m_imgBackground
{
    if (!_m_imgBackground)
    {
        _m_imgBackground = [[UIImageView alloc]init];
        _m_imgBackground.image = [UIImage imageNamed:@"voice1_"];
    }
    return _m_imgBackground;
}
- (UIImageView *)m_imgVolume
{
    if (!_m_imgVolume)
    {
        _m_imgVolume = [[UIImageView alloc]init];
        _m_imgVolume.image = [UIImage imageNamed:@"voice2_"];
    }
    return _m_imgVolume;
}
- (UILabel *)m_lblTitle
{
    if (!_m_lblTitle)
    {
        _m_lblTitle = [[UILabel alloc]init];
        _m_lblTitle.text = @"语音控制";
        _m_lblTitle.textColor = [UIColor whiteColor];
        _m_lblTitle.font = [UIFont systemFontOfSize:14];
    }
    return _m_lblTitle;
}
@end
